package com.power.project.controller;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import com.power.common.domain.ResponseDTO;
import com.power.project.enums.AccountConstant;
import com.power.project.model.Ww_user;
import io.swagger.annotations.Api;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RestController;
import com.power.project.api.IHa_mangeFeign;
import com.power.project.service.Ha_manageService;

import javax.annotation.Resource;


/**
 *   管理员控制器
 */


@RestController
@Api(value = "Ha_mangeController",tags={"管理员"})
public class Ha_manageController implements IHa_mangeFeign{

    @Resource
    private Ha_manageService ha_manageService;


    @Override
    public ResponseDTO<Void> saveMange(String userId) {
        // 获取当前会话
        SaSession saSession = StpUtil.getTokenSession();
        // 从会话中获取Ww_user对象
        Ww_user ww_user = (Ww_user) saSession.get(AccountConstant.USER);
        // 检查Ww_user对象是否为null
        Assert.notNull(ww_user, "请重新登录");
        ha_manageService.save(ww_user.getUserid(), userId);
        return ResponseDTO.succ();
    }

    @Override
    public ResponseDTO<Void> deleteMange(String userId) {
        // 获取当前会话
        SaSession saSession = StpUtil.getTokenSession();
        // 从会话中获取Ww_user对象
        Ww_user ww_user = (Ww_user) saSession.get(AccountConstant.USER);
        // 检查Ww_user对象是否为null
        Assert.notNull(ww_user, "请重新登录");
        ha_manageService.delete(ww_user.getUserid(), userId);
        return ResponseDTO.succ();
    }
}
